home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / northc / example2.lzh / top / util.c < prev   
C/C++ Source or Header  |  1990-08-30  |  934b  |  42 lines

  1. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. /*
  15.  * strsave(s) - copy s to dynamically allocated space
  16.  */
  17. char *
  18. strsave(s)
  19. register char    *s;
  20. {
  21.     char    *malloc(), *strcpy();
  22.  
  23.     return strcpy(malloc((unsigned) (strlen(s) + 1)), s);
  24. }
  25.  
  26. /*
  27.  * alloc() - malloc with error checking
  28.  */
  29. char *
  30. alloc(n)
  31. int    n;
  32. {
  33.     extern    char    *malloc();
  34.     char    *p;
  35.  
  36.     if ((p = malloc(n)) == NULL) {
  37.         fprintf(stderr, "top: out of memory\n");
  38.         exit(EXIT_FAILURE);
  39.     }
  40.     return p;
  41. }
  42.